package hot100;

import java.util.ArrayList;
import java.util.List;

public class permute {
    static List<List<Integer>> ret;
    static List<Integer> path;
    static boolean[] check;
    public List<List<Integer>> permute(int[] nums) {
        ret = new ArrayList<>();
        path = new ArrayList<>();
        check = new boolean[nums.length];
        dfs(nums);
        return ret;
    }

    void dfs(int[] nums) {
        if(path.size() == nums.length) {
            ret.add(new ArrayList<>(path));
            return;
        }
        for(int i = 0;i < nums.length;i++) {
            if(check[i] != true) {
                path.add(nums[i]);
                check[i] = true;
                dfs(nums);

                //剪枝
                check[i] = false;
                path.remove(path.size() - 1);
            }
        }
    }
}
